<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.springframework.org/schema/data/jaxb">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>代码生成器</title>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
    <script th:src="@{/jquery.js}"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">代码生成器</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item"><a href="">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div title="菜单缩放" class="kit-side-fold" ><i class="fa fa-navicon" aria-hidden="true"></i></div>
        <div class="layui-side-scroll">

            <ul class="layui-nav layui-nav-tree"  lay-filter="test" >
                <li class="layui-nav-item"><a href="">数据库当前表信息</a></li>
            </ul>
        </div>
    </div>

    <div class="layui-body">

        <!-- 内容主体区域 -->
        <div style="padding: 15px;">

            <div class="layui-row">
                <form class="layui-form" id="form" lay-filter="data_form" >
                    <div class="layui-form-item">
                        <label class="layui-form-label">数据库地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="url" id="url" required  lay-verify="required" placeholder="请输入数据库链接地址" autocomplete="off" class="layui-input" value="jdbc:mysql://47.114.135.205:8265/lykj_housing">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">数据库账号</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" id="username" required  lay-verify="required" placeholder="请输入数据库账号" autocomplete="off" class="layui-input" value="root">
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">数据库密码</label>
                        <div class="layui-input-block">
                            <input type="test" name="password" id="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" value="zobyn_2020_lwcy">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择数据库</label>
                        <div class="layui-input-block">
                            <select name="driver" id="driver" lay-verify="required">
                                <option value=""></option>
                                <option value="mysql">mysql</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn"  lay-submit="">获取数据库信息</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>


            </div>
            <div class="layui-row">
                  <table class="layui-hide" id="table" ></table>
            </div>

        </div>

    </div>

    <div class="layui-footer">
        <h5>代码生成器</h5>
    </div>
</div>
<script th:src="@{/layui/layui.all.js}"></script>
<script th:src="@{/myjs/nav.js}"></script>
<script th:inline="javascript" >

    var url = /*[[@{/table}]]*/

    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;

    });

    var tableIns=null;
    layui.use('table', function(){
        table = layui.table;
       tableIns = table.render({
            elem: '#table',
            url: url,
            method:'post',
            limit:30,
            cols: [
                [
                    {field:'tableName', width:200, title: '表名'},
                    {field:'dataName', width:200, title: '所属数据库'},
                    {field:'modifyName', width:200, title: '生成对象名'},
                    {field:'remark', width:200, title: '表备注'},
                /*    {field:'width', width:200, title: '弹窗宽度'},
                    {field:'height', width:200, title: '弹窗高度'},
                    {field:'isToken', width:200, title: '是否需要token效验'
                        ,templet: function(d){
                            var isToken=d.isToken
                            if(isToken==0){
                                return '不需要'
                            }else if (isToken==1){
                                return '需要'
                            }else{
                                return "";
                            }

                        }
                    },
                    {field:'height', width:200, title: 'excle导出'
                        ,templet: function(d){
                            var isExcle=d.isExcle
                            if(isExcle==0){
                                return '不需要'
                            }else if (isExcle==1){
                                return '需要'
                            }else{
                                return "";
                            }
                        }
                    },
                    {field:'isSwagger', width:200, title: 'swagger文档'
                        ,templet: function(d){
                            var isSwagger=d.isSwagger
                            if(isSwagger==0){
                                return '不需要'
                            }else if (isSwagger==1){
                                return '需要'
                            }else{
                                return "";
                            }
                        }
                    },
                    {field:'fieldType', width:200, title: '传输类型'
                        ,templet: function(d){
                            var fieldType=d.fieldType
                            if(fieldType==0){
                                return '字段传输'
                            }else if (fieldType==1){
                                return 'json传输'
                            }else{
                                return "";
                            }
                        }
                    },*/
                    {field:'packageName', width:200, title: '生成文件包名'},
                    {field:'id', width:800, title: '操作' ,templet: '#getFields',fixed:'right'}
                ]
            ],
        });
    });


    var data_form = layui.form;
    data_form.render(null, 'data_form');
    data_form.on('submit(data_form)',function(){
        tableIns.reload( {
            where: {
                url:$("#url").val(),
                username:$("#username").val(),
                password:$("#password").val(),
                driver:$("#driver").val()
            }
        });
        return false;
    })


    function getField(id){
        var indexUrl = /*[[@{/field/main}]]*/
        $.post(indexUrl, {'id':id}, function(id){
         field_data_index=   layer.open({
                type: 1,
                area: ['95%', '90%'],
                content: id, //注意，如果str是object，那么需要字符拼接。
                btn: ['关闭'],
                yes: function(index, layero){
                   layer.close(field_data_index);
                 }
            });
        });

    }

    var update_table_index=null;
    function updateTableInfo(id){
        var tableUrl = /*[[@{/table/toUpdate}]]*/
        $.post(tableUrl, {'id':id}, function(id){
            update_table_index= layer.open({
                type: 1,
                area: ['95%', '90%'],
                content: id //注意，如果str是object，那么需要字符拼接。
            });
        });
    }


    function toCreate(id){
        var createUrl = /*[[@{/toCreate}]]*/
            $.post(createUrl, {'id':id}, function(id){
                create_index= layer.open({
                    type: 1,
                    area: ['35%', '30%'],
                    content: id, //注意，如果str是object，那么需要字符拼接。
                    btn: ['关闭'],
                    yes: function(index, layero){
                        layer.close(1);
                    }
                });
            });
    }


    function toCreateFb(id){
        var createUrl = /*[[@{/toCreateFb}]]*/
            $.post(createUrl, {'id':id}, function(id){
                create_index= layer.open({
                    type: 1,
                    area: ['65%', '80%'],
                    content: id, //注意，如果str是object，那么需要字符拼接。
                    btn: ['关闭'],
                    yes: function(index, layero){
                        layer.close(1);
                    }
                });
            });
    }

</script>
</body>

<script type="text/html" id="getFields">
    <button class="layui-btn layui-btn-sm" type="button"  onclick="getField('{{d.id}}')">设置表字段信息</button>
    <button class="layui-btn layui-btn-sm" type="button"  onclick="updateTableInfo('{{d.id}}')">设置表基本信息</button>
    <button class="layui-btn layui-btn-sm" type="button"  onclick="toCreate('{{d.id}}')">生成单项目代码</button>
    <button class="layui-btn layui-btn-sm" type="button"  onclick="toCreateFb('{{d.id}}')">生成分布式项目代码</button>
    <button class="layui-btn layui-btn-sm" type="button"  onclick="toCreateJt('{{d.id}}')">生成金通项目代码</button>
</script>


<script type="text/html" id="toUpdateField">
    <button class="layui-btn layui-btn-sm" type="button"  onclick="toUpdateField('{{d.id}}')">设置字段基本信息</button>
</script>

</html>